import 'package:flutter/material.dart';

class ListComponent extends StatelessWidget {
  
  const ListComponent({this.data});
  final ListComponentData data;

  @override
  Widget build(BuildContext context) {

    var list  = ListView.builder(
      padding: const EdgeInsets.all(16.0),
      itemCount: data.items.length,
      itemBuilder: (context, i) {
        var item = data.items[i];
        return new ListTile(
          title: Text(item.title),
          onTap: () {
            if (item.builder != null ) {
              Navigator.of(context).push(MaterialPageRoute(builder: item.builder));
            }
          },
        );
      },
    );

    return Scaffold(
      appBar: AppBar(
        title: Text(data.title),
        elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 5.0,
      ),
      body: list
    );
  }
}

class ListComponentData {
  const ListComponentData({this.title, this.items});
  final String title;
  final List<ListItem> items;
}

// Route<T> route
class ListItem {
  const ListItem({this.title, this.builder});
  final String title;
  final WidgetBuilder builder;
}

